package mine.threadgroup;

/**
 * 线程组内统一异常处理
 *
 * @author huangchao
 * @date 2022/1/24
 */
public class NewThreadGroup {
    public static void main(String[] args) {

        ThreadGroup threadGroup = new ThreadGroup("newThreadGroup") {

            /**
             * 线程组内线程异常的统一处理
             * @param t
             * @param e
             */
            @Override
            public void uncaughtException(Thread t, Throwable e) {
                System.out.println("线程 " + t.getName() + " 抛出异常");
                super.uncaughtException(t, e);
            }
        };

        new Thread(threadGroup, () -> {
            throw new IllegalArgumentException("手动抛出异常");
        }).start();
    }
}
